package com.dehui.traders.ui.optioanl;

import android.widget.HorizontalScrollView;

import com.dehui.traders.R;
import com.dehui.traders.BR;
import com.dehui.traders.adapter.OptionCodeAdapter;
import com.dehui.traders.adapter.TableAdapter;
import com.dehui.traders.bean.RealtimeQuote;
import com.dehui.traders.config.Config;
import com.dehui.traders.databinding.ActivityMyOptionalStockBinding;
import com.dehui.traders.ui.base.AppFragment;
import com.dehui.traders.widgets.MyHScrollView;

import java.util.ArrayList;
import java.util.List;

public class MyOptiaonalStockFragemnt extends AppFragment<ActivityMyOptionalStockBinding,MyOptionalStockViewModel> implements TableAdapter.OnTableItemClick {

    private OptionCodeAdapter adapter;
    public HorizontalScrollView mTouchView;
    private List<RealtimeQuote> optionList = new ArrayList<>();

    @Override
    public int initContentView() {
        return R.layout.activity_my_optional_stock;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MyOptionalStockViewModel initViewModel() {
        return new MyOptionalStockViewModel(getContext(),this);
    }

    @Override
    public void initData() {
        super.initData();
        initToolbar("我的","我的自选");
        adapter = new OptionCodeAdapter(getContext(), optionList, this);
        binding.tabView.setFixes(Config.indexTitle)
                .setOthers(Config.optionOtherTitle)
                .setFragment(this)
                .setOnItemClick(this)
                .setAdapter(adapter).build();
    }

    @Override
    public void onItemClick(int position) {

    }

    public void onScrollChanged(int l, int t, int oldl, int oldt) {
        List<MyHScrollView> mHScrollViews = binding.tabView.getScrollViews();
        for(MyHScrollView scrollView : mHScrollViews) {
            if(mTouchView != scrollView)
                scrollView.smoothScrollTo(l, t);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        viewModel.getOptionalCodeByPhone();
    }

    public void updataList(List<RealtimeQuote> list) {
        optionList.clear();
        optionList.addAll(list);
        adapter.notifyDataSetChanged();
    }

}
